package com.quanshu.exchange.ui.gui.message.chat.redpackage;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.baselibrary.util.glide.GlideUtils;
import com.quanshu.exchange.R;
import com.quanshu.exchange.support.utils.RxViewHelper;
import com.quanshu.exchange.ui.base.BaseDialog;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.subjects.BehaviorSubject;

/**
 * Created by jye on 2018/1/17.
 */

public class DialogRedPackageExpired extends BaseDialog {

    @BindView(R.id.red_package_status)
    TextView redPackageStatus;
    @BindView(R.id.red_package_from_avatar)
    ImageView redPackageFromAvatar;
    @BindView(R.id.red_package_from_name)
    TextView redPackageFromName;
    @BindView(R.id.tip)
    TextView tip;

    public BehaviorSubject getCheckDetailSubject() {
        return checkDetailSubject;
    }

    private BehaviorSubject checkDetailSubject = BehaviorSubject.create();

    private Context context;

    public DialogRedPackageExpired(@NonNull Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_rp_expired);
        ButterKnife.bind(this);
        initListener();
        initView();
    }

    @Override
    public void init(@NonNull Context context) {
        Window window = getWindow();
//        window.setWindowAnimations(R.style.BottomAnim);
        window.setGravity(Gravity.CENTER);
        //默认的Dialog只有5/6左右的宽度，改为全屏宽度,由dialog的布局自己来决定实际显示宽度
        window.getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
    }

    private void initView() {
    }

    private void initListener() {

        RxViewHelper.getInstance().clicks(tip, aVoid -> checkDetailSubject.onNext(aVoid));

    }

    public void setViewInfo(String rpName, String fromAvatar, String fromName, int status) {
        GlideUtils.setRoundImageView(context, fromAvatar, R.drawable.default_avatar, redPackageFromAvatar);
        redPackageFromName.setText(fromName);
        if (status == 1) {
            redPackageStatus.setText("手慢了，红包派完啦！");
        } else if (status == 4) {
            redPackageStatus.setText("红包已过期！");
        }
    }

    @Override
    public boolean isCancelAble() {
        return true;
    }
}
